using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ShowBattleInfoPanel : BasePanel
{

    public Text atk;
    public Text health;
    public Text defense;
    public Image monsterImg;
    public Button quitBtn;
    public Button startBtn;

    private Transform monsterTransform;
    private MonsterDetailSO monsterDetail;
    public override void OpenPanel(string name,params object[] args)
    {
        base.OpenPanel(name);
        monsterTransform=(Transform)args[0];
        monsterDetail=(MonsterDetailSO)args[1];
        Initialize();
    }

    private void Initialize()
    {
        atk.text = monsterDetail.minAtk + "-" + monsterDetail.maxAtk;
        health.text = monsterDetail.health.ToString();
        defense.text = monsterDetail.minDefense + "-" + monsterDetail.maxDefense;
        quitBtn.onClick.AddListener(ClosePanel);
        startBtn.onClick.AddListener(StartBattle);
    }

    /// <summary>
    /// 开始战斗
    /// </summary>
    private void StartBattle()
    {
        UIManager.Instance.ClosePanel(UIConst.ShowBattleInfoPanel);
        UIManager.Instance.OpenPanel(UIConst.BattlePanel);
    }

    public override void ClosePanel()
    {
        base.ClosePanel();
    }

    private void Update()
    {
        if (monsterTransform!=null)
        {
            monsterImg.sprite = monsterTransform.GetComponent<SpriteRenderer>().sprite;
        }
    }
}
